#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int main() 
{
    int total_weight,m;
    cin>>m>>total_weight;
    int w[m];
    int v[m];
    for(int i=0;i<m;i++)
    {
    	cin>>w[i]>>v[i];
	}
    int dp[total_weight+1];
    memset(dp,0,sizeof(dp));
    for (int i=0;i<m;i++)
        for (int j=total_weight;j>=w[i]; j--)
            dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
    cout<<dp[total_weight]<<endl;
    return 0;
}
